layui.use(['layer'], function () {
    var layer = layui.layer;
    jQuery(function ($) {
        $(document).on('click', '.toolbar a[data-target]', function (e) {
            e.preventDefault();
            var target = $(this).data('target');
            $('.widget-box.visible').removeClass('visible');//hide others
            $(target).addClass('visible');//show target
        });

        $("#btnReturn").click(function () {
            $("#signup-box").removeClass("visible");
            $("#login-box").addClass('visible');
        });


        $("#btnLogin").click(function () {
            var userName = $("input[name = 'userName']").val();
            if (userName == "") {
                layer.alert('用户名不能为空.');
                return false;
            }
            var password = $("input[name = 'password']").val();
            if (password == "") {
                layer.alert('密码不能为空.');
                return false;
            }
            $("#loginForm").submit();
        });

        $("#btnSubmit").click(function () {
            var userName = $("#registerForm input[name = 'userName']").val();
            if (userName == "") {
                layer.alert('用户名不能为空.');
                return false;
            }
            var password = $("#registerForm input[name = 'password']").val();
            if (password == "") {
                layer.alert('密码不能为空.');
                return false;
            }
            var repassword = $("#registerForm input[name = 'repassword']").val();
            if (repassword == "") {
                layer.alert('确认密码不能为空.');
                return false;
            }
            if (password != repassword) {
                layer.alert('两次输入密码不一致，请重新输入.');
                return false;
            }
            var company = $("#registerForm input[name = 'company']").val();
            if (company == "") {
                layer.alert('机构名称不能为空.');
                return false;
            }

            var phone = $("#registerForm input[name = 'phone']").val();
            if (phone == "") {
                layer.alert('手机号不能为空.');
                return false;
            }
            $.ajax({
                cache: true,
                type: "POST",
                url: HuiqianUtil.getWebRootPath() + "/web/member/save.htmls",
                data: $('#registerForm').serialize(),// 你的formid
                async: false,
                dataType: "JSON",
                error: function () {
                    layer.alert("网络不稳定,请稍后登录.");
                },
                success: function (data) {
                    if (data.success) {
                        layer.open({
                            title: '温馨提示',
                            content: data.message,
                            btn: ['确定'],
                            btn1: function () {
                                window.location.href = HuiqianUtil.getWebRootPath() + "/login_new.jsp";
                            }
                        });
                    } else {
                        layer.alert(data.message);
                    }
                }
            });
        });

        $("body").keydown(function () {
            if (event.keyCode == "13") {//keyCode=13是回车键
                $('#btnLogin').click();
            }
            ;
        });

        $("#wjmm").click(function () {
            layer.open({
                type: 1,
                title: false,
                closeBtn: false,
                shade: 0.3,
                id: 'LAY_layuipro',
                btn: ['确定', '取消'],
                btnAlign: 'c',
                moveType: 1,
                content: '<div style="padding: 50px; line-height: 12px; background-color: #393D49; color: #fff; font-weight: 300;">请联系管理员重置密码.</div>',
                success: function (layero) {
                    var btn = layero.find('.layui-layer-btn');
                    btn.find('.layui-layer-btn0').attr({
                        href: 'tencent://message/?uin=401944133&Site=http://vps.shuidazhe.com&Menu=yes'
                        , target: '_blank'
                    });
                }
            });
        });

        //you don't need this, just used for changing background
        jQuery(function ($) {
            $('#btn-login-dark').on('click', function (e) {
                $('body').attr('class', 'login-layout');
                $('#id-text2').attr('class', 'white');
                $('#id-company-text').attr('class', 'blue');

                e.preventDefault();
            });
            $('#btn-login-light').on('click', function (e) {
                $('body').attr('class', 'login-layout light-login');
                $('#id-text2').attr('class', 'grey');
                $('#id-company-text').attr('class', 'blue');

                e.preventDefault();
            });
            $('#btn-login-blur').on('click', function (e) {
                $('body').attr('class', 'login-layout blur-login');
                $('#id-text2').attr('class', 'white');
                $('#id-company-text').attr('class', 'light-blue');

                e.preventDefault();
            });

        });
    });
});